
import datetime
import httpx
from localJenkins.local_jenkins import JenkinsContest

class Robot(JenkinsContest):

    def __init__(self):
        super().__init__()
        self.url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=bec34d54-4b8f-4708-82aa-001b31b750a4'

    def message(self, total, passed, failed, skipped, error) -> dict:
        data = {
            "msgtype": "markdown",
            "markdown": {
                "content":
                    '''<font color=\"warning\">测试反馈</font>\n
                    > 用例执行完毕时间:<font color=\"info\">{}</font>\n
                    > 项目名称:<font color=\"comment\">{}</font>\n
                    > 用例总数:<font color=\"comment\">{}</font>\n
                    > 通过用例数:<font color=\"info\">{}</font>\n
                    > 失败用例数:<font color=\"warning\">{}</font>\n
                    > 跳过用例数:<font color=\"warning\">{}</font>\n
                    > 错误用例数:<font color=\"warning\">{}</font>\n
                    > 构建地址：[构建地址,请点击后进入查看]({})
                    > 报告地址：[allure报告,请点击后进入查看]({})
                '''.format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
                           self.job_name, total, passed, failed, skipped, error, self.job_url,
                           self.report_url)
            },
            "mentioned_mobile_list": ["@all"]
        }

        return data

    def send_message(self, total, passed, failed, skipped, error):
        data = self.message(total, passed, failed, skipped, error)
        httpx.post(url=self.url, json=data)







